/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package QuanLyNhaCungCap;

import KetNoiSQL.KetNoiSQL;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author PhuongNga
 */
public class NhaCungCap {

    private int MaNhaCungCap;
    private String TenNhaCungCap;
    private String TenDayDu;
    private String DiaChi;
    private String SDT;
    private String Fax;
    private String Email;
    private String Web;

    public NhaCungCap() {
    }

    public int getMaNhaCungCap() {
        return MaNhaCungCap;
    }

    public void setMaNhaCungCap(int MaNhaCungCap) {
        this.MaNhaCungCap = MaNhaCungCap;
    }

    public String getTenNhaCungCap() {
        return TenNhaCungCap;
    }

    public void setTenNhaCungCap(String TenNhaCungCap) {
        this.TenNhaCungCap = TenNhaCungCap;
    }

    public String getTenDayDu() {
        return TenDayDu;
    }

    public void setTenDayDu(String TenDayDu) {
        this.TenDayDu = TenDayDu;
    }

    public String getDiaChi() {
        return DiaChi;
    }

    public void setDiaChi(String DiaChi) {
        this.DiaChi = DiaChi;
    }

    public String getSDT() {
        return SDT;
    }

    public void setSDT(String SDT) {
        this.SDT = SDT;
    }

    public String getFax() {
        return Fax;
    }

    public void setFax(String Fax) {
        this.Fax = Fax;
    }

    public String getEmail() {
        return Email;
    }

    public void setEmail(String Email) {
        this.Email = Email;
    }

    public String getWeb() {
        return Web;
    }

    public void setWeb(String Web) {
        this.Web = Web;
    }
    //Kết nối tới CSDL, gọi thủ tục spXemNhaCungCap

    public static Vector xemNhaCungCap() throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan("spXemNhaCungCap");

            while (rs.next()) {
                NhaCungCap ncc = new NhaCungCap();

                ncc.MaNhaCungCap = rs.getInt(1);
                ncc.TenNhaCungCap = rs.getString(2);
                ncc.TenDayDu = rs.getString(3);
                ncc.DiaChi = rs.getString(4);
                ncc.SDT = rs.getString(5);
                ncc.Fax = rs.getString(6);
                ncc.Email = rs.getString(7);
                ncc.Web = rs.getString(8);
                v.add(ncc);
            }

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return v;
    }
    //Lấy dữ liệu theo tên nhà cung cấp

    public static Vector layTheoTenNhaCungCap(Vector ten) throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan("spLayTheoTenNhaCungCap", ten);
            while (rs.next()) {
                NhaCungCap ncc = new NhaCungCap();
                ncc.MaNhaCungCap = rs.getInt(1);
                ncc.TenNhaCungCap = rs.getString(2);
                ncc.TenDayDu = rs.getString(3);
                ncc.DiaChi = rs.getString(4);
                ncc.SDT = rs.getString(5);
                ncc.Fax = rs.getString(6);
                ncc.Email = rs.getString(7);
                ncc.Web = rs.getString(8);
                v.add(ncc);

            }

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return v;

    }
    //Lấy ten nhà cung cấp
    public static Vector layTenNhaCungCap() throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan("spXemTenNhaCungCap");
            while (rs.next()) {
                NhaCungCap ncc = new NhaCungCap();
                ncc.TenNhaCungCap = rs.getString(1);
                v.add(ncc);

            }

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return v;

    }
    
    //Lấy theo địa chỉ nhà cung cấp
      public static Vector layTheoDiaChiNhaCungCap(Vector diaChi) throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan("spLayTheoDiaChiNhaCungCap", diaChi);
            while (rs.next()) {
                NhaCungCap ncc = new NhaCungCap();
                ncc.MaNhaCungCap = rs.getInt(1);
                ncc.TenNhaCungCap = rs.getString(2);
                ncc.TenDayDu = rs.getString(3);
                ncc.DiaChi = rs.getString(4);
                ncc.SDT = rs.getString(5);
                ncc.Fax = rs.getString(6);
                ncc.Email = rs.getString(7);
                ncc.Web = rs.getString(8);
                v.add(ncc);

            }

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return v;

    }
    //Lấy dữ liệu theo tên và địa chỉ nhà cung cấp
    public static Vector layTen_DiaChiNhaCungCap(Vector ten_DiaChi) throws SQLException {
        Vector v = new Vector();
        try {
            ResultSet rs = KetNoiSQL.thucHienTruVan("spLayTen_DiaChiNhaCungCap", ten_DiaChi);
            while (rs.next()) {
                NhaCungCap ncc = new NhaCungCap();
                ncc.MaNhaCungCap = rs.getInt(1);
                ncc.TenNhaCungCap = rs.getString(2);
                ncc.TenDayDu = rs.getString(3);
                ncc.DiaChi = rs.getString(4);
                ncc.SDT = rs.getString(5);
                ncc.Fax = rs.getString(6);
                ncc.Email = rs.getString(7);
                ncc.Web = rs.getString(8);
                v.add(ncc);

            }

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return v;

    }
    //Thêm nhà cung cấp

    public static int themNhaCungCap(NhaCungCap ncc) throws SQLException {
        int i = 0;
        try {
            Vector dsThamSo = new Vector();
            dsThamSo.add(ncc.TenNhaCungCap);
            dsThamSo.add(ncc.TenDayDu);
            dsThamSo.add(ncc.DiaChi);
            dsThamSo.add(ncc.SDT);
            dsThamSo.add(ncc.Fax);
            dsThamSo.add(ncc.Email);
            dsThamSo.add(ncc.Web);
            i = KetNoiSQL.thucHienCapNhat("spThemNhaCungCap", dsThamSo);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return i;
    }
    //Cập nhật nhà cung cấp

    public static int capNhatNhaCungCap(NhaCungCap ncc) throws SQLException {
       int i = 0;
        try {
            Vector dsThamSo = new Vector();
            dsThamSo.add(ncc.MaNhaCungCap);
            dsThamSo.add(ncc.TenNhaCungCap);
            dsThamSo.add(ncc.TenDayDu);
            dsThamSo.add(ncc.DiaChi);
            dsThamSo.add(ncc.SDT);
            dsThamSo.add(ncc.Fax);
            dsThamSo.add(ncc.Email);
            dsThamSo.add(ncc.Web);
            i = KetNoiSQL.thucHienCapNhat("spCNNhaCungCap", dsThamSo);
        } catch (SQLException sqlex) {
          
        }
        return i;
    }
    //Xóa nhà cung cấp

    public static int xoaNhaCungCap(String ten) throws SQLException {
        int i = 0;
        try {
            Vector dsThamSo = new Vector();
            dsThamSo.add(ten);
            i = KetNoiSQL.thucHienCapNhat("spXoaNhaCungCap", dsThamSo);
        } catch (SQLException sqlex) {
        }
        return i;
    }
}
